package com.xmfh.wemedia.util;

import com.xmfh.wemedia.controller.DdVideoController;
import lombok.Data;
import org.springframework.stereotype.Component;

import java.io.File;
import java.net.URISyntaxException;

@Data
@Component
public class FileDirectory {
    /**
     * 获取视频文件目录以及封面文件目录
     */
    private static File localVideoStorage;
    private static File localCoverStorage;
    private static File localTargetVideoStorage;
    private static File localTargetCoverStorage;

    static {
        File file = new File("/Users/yaotonglu/IdeaProjects/wemedia/src/main/resources/static");

        File localTargetFile = null;

        try {
            localTargetFile = new File(DdVideoController.class.getClassLoader().getResource("./static").toURI());
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }

        localVideoStorage = new File(file, "video");
        localCoverStorage = new File(file, "img");

        if (!localVideoStorage.exists()) {
            localVideoStorage.mkdirs();
        }

        if (!localCoverStorage.exists()) {
            localCoverStorage.mkdirs();
        }

        localTargetVideoStorage = new File(localTargetFile, "video");
        localTargetCoverStorage = new File(localTargetFile, "img");

        if (!localTargetVideoStorage.exists()) {
            localTargetVideoStorage.mkdirs();
        }

        if (!localTargetCoverStorage.exists()) {
            localTargetCoverStorage.mkdirs();
        }
    }

    public File getLocalVideoStorage() {
        return localVideoStorage;
    }

    public File getLocalCoverStorage() {
        return localCoverStorage;
    }

    public File getLocalTargetVideoStorage() {
        return localTargetVideoStorage;
    }

    public File getLocalTargetCoverStorage() {
        return localTargetCoverStorage;
    }
}
